define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'caiwu/tixian/index' + location.search,
                    add_url: 'caiwu/tixian/add',
                    edit_url: 'caiwu/tixian/edit',
                    del_url: 'caiwu/tixian/del',
                    multi_url: 'caiwu/tixian/multi',
                    import_url: 'caiwu/tixian/import',
                    table: 'tixian',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                showToggle: false, // 浏览模式切换
                showColumns: true, // 允许选择显示字段
                showExport: true, // 导出选项
                exportDataType: "basic", //导出当前页
                exportTypes: ['excel'],
                searchFormVisible: false, // 通用搜索 默认是否显示
                search: false, // 是否关闭搜索
                trimOnSearch: true, // 自动删除搜索空格
                pageList: [10, 20, 30, 50],
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [{
                            checkbox: true
                        },
                        // {
                        //     field: 'id',
                        //     title: __('Id')
                        // },
                        {
                            field: 'admin_id',
                            title: __('Admin_id')
                        },
                        // {
                        //     field: 'user_id',
                        //     title: __('User_id')
                        // },
                        {
                            field: 'money',
                            title: __('Money'),
                            operate: 'BETWEEN'
                        },
                        {
                            field: 'money2',
                            title: __('Money2'),
                            operate: 'BETWEEN'
                        },
                        {
                            field: 'statuss',
                            title: __('Statuss'),
                            searchList: {
                                "0": __('打款中'),
                                "1": __('Statuss 1'),
                                "2": __('Statuss 2'),
                                "-1": __('待处理'),
                            },
                            //状态:0=打款中,1=审核成功,2=失败,-1=待处理
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'msg',
                            title: __('Msg'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'type',
                            title: __('Type'),
                            searchList: {
                                "1": __('Type 1'),
                                "2": __('Type 2')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'addtime',
                            title: __('Addtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'orderno',
                            title: __('Orderno'),
                            operate: 'LIKE'
                        },
                        {
                            field: 'order',
                            title: __('Order'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [{
                                name: "ajax",
                                text: '处理提现',
                                title: __("处理提现"),
                                classname: "btn btn-xs btn-info btn-magic btn-ajax",
                                icon: "fa fa-bolt",
                                confirm: "确认吗？",
                                refresh: true,
                                hidden: visible,
                                url: "caiwu/tixian/hand?ids={ids}",
                                success: function (data, ret) {
                                    Layer.alert(ret.msg);
                                    // location.reload();
                                    //+ ",返回数据：" + JSON.stringify(data)
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    // return false;
                                }
                            }],
                        }
                    ]
                ]
            });
            $(document).on('click', '.btn-withdraw', function (event) {
                var url = 'caiwu/tixian/withdraw';
                var msg = '余额提现';
                // var area = ['50%', '50%'];
                var options = {
                    shadeClose: false,
                    shade: [0.3, '#393D49'],
                    // area: area,
                    callback: function () {}
                };
                Fast.api.open(url, msg, options);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        // withdraw: function () {
        //     Controller.api.bindevent();
        // },
        withdraw: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});